<template>
  <el-main>
    <el-form :model="information" label-width="80px" style="margin-top:30px;width: 500px">
      <el-form-item label="工号" prop="number">
        <el-tag style="width:300px;font-size:30px">{{information.number}}</el-tag>
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-tag style="width:300px;font-size:30px">{{information.name}}</el-tag>
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-tag style="width:300px;font-size:30px">{{information.sex}}</el-tag>
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-tag style="width:300px;font-size:30px">{{information.age}}</el-tag>
      </el-form-item>
      <el-form-item label="入职时间" prop="yearIn">
        <el-tag style="width:300px;font-size:30px">{{information.yearIn}}</el-tag>
      </el-form-item>
    </el-form>
  </el-main>
</template>

<script>
import { postRequestByParams } from "../utils/api";

export default {
  data() {
    return {
      username: "",
      number: "",
      information: {
        number: "",
        name: "",
        sex: "",
        age: "",
        yearIn: ""
      }
    };
  },
  methods: {
    getEmployeeInfomation: function() {
      var _this = this;
      postRequestByParams("/employee/get-one-employee", {
        number: _this.number
      }).then(resp => {
        if (resp.status == 200) {
          var json = resp.data;
          _this.information = json;
        }
      });
    },
    getAllInformation: function() {
      var _this = this;
      postRequestByParams("/account/get-number", {
        username: _this.username
      }).then(resp => {
        if (resp.status == 200) {
          var json = resp.data;
          if (json.message == "success") {
            _this.number = json.data;
            _this.getEmployeeInfomation();
          } else {
            this.$alert("请绑定工号", "警告！", {
              confirmButtonText: "确定"
            });
          }
        }
      });
    }
  },
  mounted() {
    this.username = sessionStorage.getItem("username");
    this.getAllInformation();
  }
};
</script>

<style>
</style>